/*
 *  Copyright (C) 2011 felixtheripper <felixtheripper_AT_gmail.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package org.myorg.ctm.etk.gui.swg.display.frame;

import java.awt.BorderLayout;
import java.util.Vector;
import javax.swing.JComponent;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.help.HelpBroker;
import org.myorg.shr.gui.swg.lang.IShrObj;

import org.myorg.ctm.etk.gui.swg.display.menubar.*;
import org.myorg.ctm.etk.gui.swg.display.panel.*;
import org.myorg.ctm.etk.gui.swg.display.tabbedpane.*;
import org.myorg.ctm.etk.gui.swg.display.toolbar.*;
import org.myorg.ctm.etk.gui.swg.util.property.PrpNamingEtk;
import org.myorg.ctm.etk.naming.NmgFrench;

/**
 *
 * @author felixtheripper
 *
 * email: felixtheripper_AT_gmail.com
 * ... please remove "_AT_" from the above string to get the right email address
 *
 */

public class FrmPrintableMainEtk extends FrmPrintableMainAbs
{

    public FrmPrintableMainEtk()
    {
        super(FrmPrintableMainEtk._INT_DIMW_, FrmPrintableMainEtk._INT_DIMH_);
        super.setDefaultCloseOperation(javax.swing.JFrame.DO_NOTHING_ON_CLOSE);

        this._vecObj_ = new Vector<IShrObj>();

        this._mbrAdministrator_ = new MbrPerspAdministrator();
        this._mbrPractitioner_ = new MbrPerspPractitioner();
        this._mbrSecretary_ = new MbrPerspSecretary();

        this._tbrAdministrator_ = new TbrPerspAdministrator();
        this._tbrPractitioner_ = new TbrPerspUserPractitioner();
        this._tbrSecretary_ = new TbrPerspUserSecretary();

        this._tpnAdministrator_ = new TPPerspAdministrator();
        this._tpnPractitioner_ = new TPPerspPractitioner();
        this._tpnSecretary_ = new TPPerspSecretary();


        this._pnlStatusbarAdministrator_ = new PnlStatusBarAdministrator(
                this._mbrAdministrator_.getSubElements(),
                this._tbrAdministrator_.getComponents()
                );

        this._pnlStatusbarPractitioner_ = new PnlStatusBarPractitioner(
                this._mbrPractitioner_.getSubElements(),
                this._tbrPractitioner_.getComponents()
                );

        this._pnlStatusbarSecretary_ = new PnlStatusBarSecretary(
                this._mbrSecretary_.getSubElements(),
                this._tbrSecretary_.getComponents()
                );


        // ----

        this._vecObj_.add(this._mbrAdministrator_);
        this._vecObj_.add(this._tbrAdministrator_);
        this._vecObj_.add(this._tpnAdministrator_);
        this._vecObj_.add(this._pnlStatusbarAdministrator_);

        this._vecObj_.add(this._mbrPractitioner_);
        this._vecObj_.add(this._tbrPractitioner_);
        this._vecObj_.add(this._tpnPractitioner_);
        this._vecObj_.add(this._pnlStatusbarPractitioner_);

        this._vecObj_.add(this._mbrSecretary_);
        this._vecObj_.add(this._tbrSecretary_);
        this._vecObj_.add(this._tpnSecretary_);
        this._vecObj_.add(this._pnlStatusbarSecretary_);

    }
    
    private void _setPerspective_(
            String strTitleSuffix,
            JMenuBar mbr,
            JToolBar tbr,
            TPPerspAbs tpnContents,
            JPanel pnlStatus)
    {
        JMenuBar mbrPrev = super.getJMenuBar();

        if (mbrPrev != null)
            super.remove(mbrPrev);

        super.setJMenuBar(mbr);

        super.getContentPane().removeAll();
        super.getContentPane().add(tbr, BorderLayout.NORTH);
        super.getContentPane().add(tpnContents, BorderLayout.CENTER);
        super.getContentPane().add(pnlStatus, BorderLayout.SOUTH);
      
        String strTitle = System.getProperty(PrpNamingEtk.STR_PRP_APPLI_TITLE);

        if (strTitleSuffix != null)
        {
            strTitle += " - ";
            strTitle += strTitleSuffix;
        }
        super.setTitle(strTitle);
        JComponent cmp = (JComponent) super.getContentPane();
        cmp.revalidate();
        cmp.repaint();
    }

    public void userPerspectiveAdministratorHandler()
    {
        _setPerspective_(
                NmgFrench.F_STR_NAME_ADMINISTRATOR,
                this._mbrAdministrator_,
                this._tbrAdministrator_,
                this._tpnAdministrator_,
                this._pnlStatusbarAdministrator_);
    }

    public void userPerspectivePractitionerHandler()
    {
        _setPerspective_(
                NmgFrench.F_STR_NAME_PRACTITIONER,
                this._mbrPractitioner_,
                this._tbrPractitioner_,
                this._tpnPractitioner_,
                this._pnlStatusbarPractitioner_);
    }

    public void userPerspectiveSecretaryHandler()
    {
        _setPerspective_(
                NmgFrench.F_STR_NAME_SECRETARY,
                this._mbrSecretary_,
                this._tbrSecretary_,
                this._tpnSecretary_,
                this._pnlStatusbarSecretary_);
    }

    @Override
    public void setEnabledHelpGettingStarted(HelpBroker hbr)
    {
        for (int i=0; i<this._vecObj_.size(); i++)
        {
            IShrObj obj = this._vecObj_.elementAt(i);

            if (obj instanceof MbrPerspAbs)
            {
                ((MbrPerspAbs) obj).setEnabledHelpGettingStarted(hbr);
            }
        }
    }

    @Override
    public void setEnabledHelpOnContext()
    {
            /*if (this._mbr_ != null)
                    this._mbr_.setEnabledHelpOnContext();

            if (this._pnlContents_ != null)
            this._pnlContents_.setEnabledHelpOnContext();*/
    }

    @Override
    public void setEnabledHelpSourceAndTrack(HelpBroker hbr)
    {
        for (int i=0; i<this._vecObj_.size(); i++)
        {
            IShrObj obj = this._vecObj_.elementAt(i);

            if (obj instanceof MbrPerspAbs)
            {
                ((MbrPerspAbs) obj).setEnabledHelpSourceAndTrack(hbr);
            }

            if (obj instanceof TbrPerspAbs)
            {
                ((TbrPerspAbs) obj).setEnabledHelpSourceAndTrack(hbr);
            }
        }
    }

    @Override
    public boolean init()
    {
        for (int i=0; i<this._vecObj_.size(); i++)
        {
            IShrObj obj = this._vecObj_.elementAt(i);

            if (! obj.init())
                return false;
        }

        return true;
    }

    @Override
    public void destroy()
    {
        for (int i=0; i<this._vecObj_.size(); i++)
        {
            IShrObj obj = this._vecObj_.elementAt(i);

            if (obj == null)
                continue;

            obj.destroy();
        }

        this._vecObj_.clear();
        this._vecObj_ = null;
    }

    // ?? to be replaced by Set s = Collections.synchronizedSet(new HashSet(...));
    private Vector<IShrObj> _vecObj_ = null;

    // Status bar which reports mouseover action messages
    private PnlStatusBarAbs _pnlStatusbarAdministrator_ = null;
    private PnlStatusBarAbs _pnlStatusbarPractitioner_ = null;
    private PnlStatusBarAbs _pnlStatusbarSecretary_ = null;

    private MbrPerspAbs _mbrAdministrator_ = null;
    private MbrPerspAbs _mbrPractitioner_ = null;
    private MbrPerspAbs _mbrSecretary_ = null;

    private TbrPerspAbs _tbrAdministrator_ = null;
    private TbrPerspAbs _tbrPractitioner_ = null;
    private TbrPerspAbs _tbrSecretary_ = null;

    private TPPerspAbs _tpnAdministrator_ = null;
    private TPPerspAbs _tpnPractitioner_ = null;
    private TPPerspAbs _tpnSecretary_ = null;

    
    final static private int _INT_DIMW_ = 900;
    final static private int _INT_DIMH_ = 700;

}
